/**
	*****************************************************************************
	* @file     cmem7_usart.h
	*
	* @brief    CMEM7 uart header file
	*
	*
	* @version  V1.0
	* @date     3. September 2013
	*
	* @note               
	*           
	*****************************************************************************
	* @attention
	*
	* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
	* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
	* TIME. AS A RESULT, CAPITAL-MICRO SHALL NOT BE HELD LIABLE FOR ANY DIRECT, 
	* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
	* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
	* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
	*
	* <h2><center>&copy; COPYRIGHT 2013 Capital-micro </center></h2>
	*****************************************************************************
	*/

#ifndef __CMEM7_USART_H
#define __CMEM7_USART_H

#ifdef __cplusplus
 extern "C" {
#endif

#include "cmem7.h"
#include "cmem7_conf.h"
  
#define IS_USART_ALL_PERIPH(PERIPH) (((PERIPH) == USART0) || \
                                     ((PERIPH) == USART1) || \
                                     ((PERIPH) == USART2))

#define USART_StopBits_0_5                 0
#define USART_StopBits_1                   1
#define USART_StopBits_1_5                 2
#define USART_StopBits_2                   3
#define IS_USART_STOPBITS(STOPBITS) (((STOPBITS) == USART_StopBits_1) || \
                                     ((STOPBITS) == USART_StopBits_0_5) || \
                                     ((STOPBITS) == USART_StopBits_2) || \
                                     ((STOPBITS) == USART_StopBits_1_5))

#define USART_Parity_Even                  0
#define USART_Parity_Odd                   1
#define USART_Parity_None                  2
#define IS_USART_PARITY(PARITY) (((PARITY) == USART_Parity_Even) || \
                                 ((PARITY) == USART_Parity_Odd) || \
																 ((PARITY) == USART_Parity_None))										 

#define USART_Int_RxNotEmpty               0x00000001    
#define USART_Int_TxEmpty                  0x00000002
#define USART_Int_TxHalfEmpty              0x00000004
#define USART_Int_TxTimeoutNotEmpty        0x00000008
#define USART_Int_TxTimeoutEmpty           0x00000010
#define USART_Int_RxHalfFull               0x00000020
#define USART_Int_TxFull                   0x00000040
#define USART_Int_ParityError              0x00000080
#define USART_Int_FrameError               0x00000100
#define USART_Int_OverrunError             0x00000200
#define USART_Int_RxThresholdReach         0x00000400
#define USART_Int_All                      0x000007FF

#define IS_USART_INT(INT)        (((INT) & ~USART_Int_All) == 0)

typedef struct
{
  uint32_t USART_BaudRate;            /*!< Baudrate */																	  
	uint8_t USART_StopBits;             /*!< Specifies the number of stop bits transmitted. */
  uint8_t USART_Parity;               /*!< Specifies the parity mode. */
	BOOL USART_LoopBack;                /*!< loop back mode */
	BOOL USART_RxEn;                    /*!< receive enable bit */
	BOOL USART_CtsEn;                   /*!< Clear to set */
} USART_InitTypeDef;

void USART_Init(USART0_Type* USARTx, USART_InitTypeDef *init);
void USART_EnableInt(USART0_Type* USARTx, uint32_t Int, BOOL enable);
void USART_Enable(USART0_Type* USARTx, BOOL enable);
BOOL USART_GetIntStatus(USART0_Type* USARTx, uint32_t Int);
void USART_ClearInt(USART0_Type* USARTx, uint32_t Int);
/* return value is actual write data size */
uint8_t USART_Write(USART0_Type* USARTx, uint8_t Size, uint8_t* Data);
/* return value is actual read data size */
uint8_t USART_Read(USART0_Type* USARTx, uint8_t Size, uint8_t* Data);


#ifdef __cplusplus
}
#endif

#endif /* __CMEM7_USART_H */
/**
  * @}
  */ 

/**
  * @}
  */ 

/**
  * @}
  */ 

/******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
